<template>
  <div>
    <el-tabs type="card" v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="全部" name="whole">
        <span slot="label"><i class="el-icon-document"></i> 全部</span>
      </el-tab-pane>
      <el-tab-pane label="今天" name="today"> </el-tab-pane>
      <el-tab-pane label="本周" name="week"></el-tab-pane>
      <el-tab-pane label="本月" name="month"></el-tab-pane>
    </el-tabs>
    <div v-loading="loading" element-loading-text="加载中...">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="username" label="用户名" align="center">
        </el-table-column>
        <el-table-column prop="datetime" label="时间" align="center">
        </el-table-column>
        <el-table-column prop="typevalue" label="登录类型" align="center">
        </el-table-column>
        <el-table-column prop="reason" label="登录状态" align="center">
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      :current-page="startPage"
      :page-size="pageSize"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
      background
      layout="total,sizes,prev, pager, next"
      :total="this.total"
    >
    </el-pagination>
  </div>
</template>

<script>
import { ApiUserLog } from "../../../api/api";
export default {
  data() {
    return {
      activeName: "today",
      name: "",
      loading: true,
      tableData: [],
      //分页
      startPage: 1,
      pageSize: 10,
      total: 0,
    };
  },
  created() {
    ApiUserLog({
      name: "today",
    }).then((res) => {
      this.tableData = res.data;
      this.total = res.count;
      this.loading = false;
    });
  },
  methods: {
    handleClick(tab, event) {
      this.name = tab.name;
      this.pageSize = 10;
      this.loading = true;
      ApiUserLog({
        name: tab.name,
      }).then((res) => {
        this.tableData = res.data;
        this.total = res.count;
        this.loading = false;
      });
    },
    handleCurrentChange(startPage) {
      this.startPage = startPage;
      this.handlePublic();
    },
    handleSizeChange(size) {
      this.pageSize = size;
      this.handlePublic();
    },
    handlePublic(data) {
      this.loading = true;
      ApiUserLog({
        name: this.name,
        currenPage: this.startPage,
        limit: this.pageSize,
      }).then((res) => {
        this.tableData = res.data || data;
        this.loading = false;
      });
    },
  },
};
</script>
<style scoped>
</style>
